package subject_set.lanqiao.moli;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * @author haomin
 * @date 2022/11/06 11:45
 **/
public class Num10 {
    // DCBA
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()){
            String str = in.nextLine();
            Set set1 = new HashSet();
            for (int i = 0; i < str.length(); i++) {
                set1.add(str.charAt(i));
            }
            int min =0,con=0;
            for (int i = 0; i < str.length(); i++) {
                Set set =new HashSet(set1);
                int n =i;
                char j ='a';
                while(!set.isEmpty()) {
                    if (j==str.charAt(n)){
                        break;
                    }
                    set.remove(str.charAt(n));
                    j =str.charAt(n);
                    int tmp = n+(str.charAt(n)-64);
                    if (n==0) {
                    }
                    else if (tmp<n) {
                        n=tmp;
                    }
                    else if (tmp>=n) {
                        n =tmp%n;
                    }
                }
                if (i==0){
                    con = set.size();
                }
                if (set.size()< con ){
                    min =i;
                }
            }

            System.out.println(min);
        }
    }
}